/**
 * 根据当前时间、交易日期、允许评论的时间段，判断当前是否允许聊天
 * @param  {Date} curDate   [当前时间]
 * @param  {Date} tradeDate [description]
 * @param  {Array} talkTime  [{
 *                           b: '09:00:00',//begin
 *                           e: '17:00:00'//end
 *                           }]
 * @return {Boolean}           [description]
 */
export default function (curDate, tradeDate, talkTime){
  var curTime = curDate.getTime();
  for (var i = 0; i < talkTime.length; i++) {
    let bs = talkTime[i].b.split(':');
    let es = talkTime[i].e.split(':');
    let startTime, endTime;
    switch(bs.length){
      case 4:
        startTime = tradeDate.setHours(bs[0], bs[1], bs[2], bs[3]);
        break;
      case 3:
        startTime = tradeDate.setHours(bs[0], bs[1], bs[2], 0);
        break;
      case 2:
        startTime = tradeDate.setHours(bs[0], bs[1], 0, 0);
        break;
      case 1:
        startTime = tradeDate.setHours(bs[0], 0, 0, 0);
        break;
      case 0:
        startTime = tradeDate.setHours(9, 0, 0, 0)
        break;
    }
    switch(es.length){
      case 4:
        endTime = tradeDate.setHours(es[0], es[1], es[2], es[3]);
        break;
      case 3:
        endTime = tradeDate.setHours(es[0], es[1], es[2], 999);
        break;
      case 2:
        endTime = tradeDate.setHours(es[0], es[1], 59, 999);
        break;
      case 1:
        endTime = tradeDate.setHours(es[0], 59, 59, 999);
        break;
      case 0:
        endTime = tradeDate.setHours(9, 59, 59, 999)
        break;
    }
    if(startTime <= curTime && curTime <= endTime) return true;
  }
  return false;
}